#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    setFixedSize(923, 496);
    ui->widget->setAttribute(Qt::WA_Hover, true);
    ui->widget->installEventFilter(this);
    propertyAnimation = new QPropertyAnimation(ui->widget, "geometry");
    propertyAnimation->setEasingCurve(QEasingCurve::InOutQuint);
    propertyAnimation->setDuration(200);

    int width_y_change = 400;
    width_y = ui->widget->width();				//width和height都是主窗口类的私有变量
    height_y = ui->widget->height();
    propertyAnimation->setStartValue(QRect(-1, 10, width_y - width_y_change - 10, height_y));		//参数代表左，上，右，下坐标

}

void Widget::resizeEvent(QResizeEvent* event)
{
    int width_y_change = 400;
    width_y = ui->widget->width();				//width和height都是主窗口类的私有变量
    height_y = ui->widget->height();
    propertyAnimation->setStartValue(QRect(-1, 10, width_y - width_y_change - 10, height_y));		//参数代表左，上，右，下坐标
    propertyAnimation->setEndValue(QRect(-1, 10, width_y-width_y_change + 30, height_y));

}

bool Widget::eventFilter(QObject* obj, QEvent* event)
{
    if (obj == ui->widget)
    {
        if (event->type() == QEvent::HoverEnter)	//鼠标进入黄色侧边栏中悬浮，正向播动画
        {
            propertyAnimation->setDirection(QAbstractAnimation::Forward);
            propertyAnimation->start();
            return true;
        }
        else if (event->type() == QEvent::HoverLeave) //鼠标离开黄色侧边栏，反向播动画
        {
            propertyAnimation->setDirection(QAbstractAnimation::Backward);
            propertyAnimation->start();
            return false;
        }
    }
    return QWidget::eventFilter(obj, event);
}

Widget::~Widget()
{
    delete ui;
}
